﻿using BookModel;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
    //图书状态表
  
   public class BookStateInfoDAL
   {
       #region 查询所有图书借阅状态
       public List<BookStateInfo> GetState()
       {
           string sql = "select *from BookStateInfo";
           List<BookStateInfo> lbs = new List<BookStateInfo>();
           if (SQLHelp.OpenConn())
           {
               SqlDataReader sdr = SQLHelp.ExecReader(sql);
               if (sdr!=null)
               {
                   while (sdr.Read())
                   {
                       lbs.Add(new BookStateInfo
                       {
                           BookStateID = (int)sdr["BookStateID"],
                           BID=(int)sdr["BID"],
                           BookState=sdr["BookState"] as string,
                           remark=sdr["remark"] as string
                       });
                   }
               }
               SQLHelp.CloseConn();
           }
           return lbs;
       }
       #endregion
       public List<BookModel.BookStateInfo> SelectBookStateInfo()
       {
           //创建图书状态对象信息
           List<BookModel.BookStateInfo> bookstateibfo = new List<BookStateInfo>();
           DataTable dt = new DataTable();

           //从数据库中查询图书状态信息
           dt = SQLHelp.FillTable(@"select B.BookStateID,B.BID,A.Bname,B.BookState,B.remark from BookInfo A,BookStateInfo B
where A.BID=B.BID ");

           //如果查询到结果
           if ((dt != null) && (dt.Rows.Count > 0))
           {
               //对象封装
               foreach (DataRow dr in dt.Rows)
               {
                   BookModel.BookStateInfo bookState = new BookModel.BookStateInfo();
                   bookState.BookStateID = (int)dr["BookStateID"];
                   bookState.BID = (int)dr["BID"];
                   bookState.Bname = dr["Bname"] as string;
                   bookState.BookState = dr["BookState"] as string;
                   bookState.remark = dr["remark"] as string;

                   bookstateibfo.Add(bookState);
               }
           }
           return bookstateibfo;
       }
   }
}
